home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Telephone Manager / Stiletto Sources / Sources / TestModule.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-05  |  3.7 KB  |  135 lines  |  [TEXT/MPS ]

  1. /************************************************************************************************/
  2. /*                                                                                                */
  3. /*    Program Name:    Stiletto                                                                    */
  4. /*                                                                                                */
  5. /*    File Name:        TestModule.c                                                                */
  6. /*                                                                                                */
  7. /*    © Apple Computer, Inc. 1991-1995                                                            */
  8. /*    All Rights Reserved                                                                            */
  9. /*                                                                                                */
  10. /*    Revision History:                                                                            */
  11. /*                                                                                                */
  12. /*        Date        Who                    Modification                                            */
  13. /*                                                                                                */
  14. /*        1991-07-10    Chris Halim            Original version                                        */
  15. /*        1995-06-26    Jaakko Railo        Version 2.0                                                */
  16. /*                                                                                                */
  17. /************************************************************************************************/
  18.  
  19. /****************************************** DESCRIPTION ******************************************
  20.  
  21. *************************************************************************************************/
  22.  
  23. /******************************************** HEADERS *******************************************/
  24.  
  25. #include "Aliases.h"
  26. #include "Resources.h"
  27. #include "string.h"
  28.  
  29. #ifndef __CALLBACKROUTINES__
  30. #include "CallBackRoutines.h"
  31. #endif
  32.  
  33. #ifndef __LOGWINDOW__
  34. #include "LogWindow.h"
  35. #endif
  36.  
  37. #ifndef __TERMWINDOW__
  38. #include "TermWindow.h"
  39. #endif
  40.  
  41. #include "TestModule.h"
  42.  
  43. #ifndef __UTILITIES__
  44. #include "Utilities.h"
  45. #endif
  46.  
  47. /****************************************** DEFINITIONS *****************************************/
  48.  
  49. /****************************************** PROTOTYPES ******************************************/
  50.  
  51. /******************************************** GLOBALS *******************************************/
  52.  
  53. extern    LogWindowPtr    gLogWindow;
  54. extern    TelWindowPtr    gTelWindow;
  55.  
  56. extern    EntryPointUPP    gEntryPointUPP;
  57.  
  58. /************************************************************************************************/
  59. /************************************************************************************************/
  60.  
  61.  
  62. void    ExecuteAnyModule (void)
  63. {
  64.     short                numOfTypes = 1;
  65.     StandardFileReply    reply;
  66.     SFTypeList            typeList;
  67.     
  68.     typeList[0] = kModuleType;
  69.     
  70.     StandardGetFile (nil, numOfTypes, typeList, &reply);
  71.     
  72.     if (reply.sfGood)        
  73.         ExecuteModule (&reply.sfFile);
  74. }
  75.  
  76.  
  77. void    ExecuteModule (FSSpecPtr theFile)
  78. {
  79.     Handle        theModule = nil;
  80.     CHRSBlock    *paramBlock;
  81.     short        savedResFile;
  82.     short        errCode;
  83.     short         moduleRefNum;
  84.     Boolean        targetIsFolder, wasAliased;
  85.     Str255        name;
  86.     
  87.     if (paramBlock = (CHRSBlock *) NewPtrClear (sizeof (CHRSBlock)))
  88.     {
  89.         errCode = ResolveAliasFile (theFile, true, &targetIsFolder, &wasAliased);
  90.     
  91.         moduleRefNum = FSpOpenResFile (theFile, fsRdPerm);
  92.         
  93.         if (moduleRefNum != -1)
  94.         {
  95.             savedResFile = CurResFile ();
  96.             UseResFile (moduleRefNum);
  97.             
  98.             theModule = Get1Resource (kModuleType, kModuleID);
  99.             if (theModule != nil) {
  100.                 HLock (theModule);
  101.                 
  102.                 paramBlock->version        = kTestModuleVersion;
  103.                 
  104.                 paramBlock->entryPoint    = (UniversalProcPtr) gEntryPointUPP;
  105.                 
  106.                 (void) strncpy ((char *) name, (char *) &theFile->name[1], theFile->name[0]);
  107.                 name[theFile->name[0]] = '\0';
  108.                 
  109.                 PutLine (gLogWindow, "••••• %s started •••••", name);
  110.     
  111.                 errCode = CallTestModuleProc ((TestModuleProcPtr) *theModule, paramBlock);
  112.     
  113.                 switch (errCode)
  114.                 {
  115.                     case noErr :
  116.                         break;                    
  117.                     case kWrongVersion :
  118.                         PutLine (gLogWindow, "Incompatible module version");
  119.                         break;                        
  120.                     default :
  121.                         PutLine (gLogWindow, "Unable to execute test module : %d", errCode);
  122.                 }
  123.                 PutLine (gLogWindow, "••••• %s ended •••••", name);
  124.                 
  125.                 HUnlock (theModule);
  126.                 ReleaseResource (theModule);
  127.             }
  128.             else
  129.                 AlertUser ("\pUnable to find the CHRS resource", ResError());
  130.             
  131.             UseResFile (savedResFile);
  132.             CloseResFile (moduleRefNum);
  133.         }
  134.     }
  135. }